package com.ssyt.cdp.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 * 
 * @author Administrator
 *
 */
public class DateUtil {

	public static final String STANDARD_DATE_PATTERN = "yyyy-MM-dd";
	public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";

	private DateUtil() {
		throw new RuntimeException("不能实例化此对象！");
	}

	/**
	 * Date => String
	 * 
	 * @param date
	 * @return
	 */
	public static String format(Date date, String pattern) {
		return new SimpleDateFormat(pattern).format(date);
	}

	public static String format(Date date) {
		return format(date, DEFAULT_PATTERN);
	}

	/**
	 * String => Date
	 * 
	 * @param dateStr
	 * @param pattern
	 * @return
	 */
	public static Date parse(String dateStr, String pattern) {
		try {
			return new SimpleDateFormat(pattern).parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Date parse(String dateStr) {
		return parse(DEFAULT_PATTERN, dateStr);
	}

	public static void main(String[] args) {
		Date date = new Date();
		System.out.println(DateUtil.format(date));
	}
}
